package com.winter.util.rabbitMqUtil;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.TimeoutException;

/**
 *
 */
@Component
public class Producer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send1() {
        String sendMsg = "ceshi " + new Date();
        System.out.println("Sender1 : " + sendMsg);
        this.rabbitTemplate.convertAndSend("DIRECT_EXCHANGE", "ceshi.best",sendMsg);
    }

    public void send2() {
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(UUID.randomUUID().toString());
        String sendMsg = "--------------------------------测试 " + new Date();
        System.out.println("Sender2 : " + sendMsg);
        this.rabbitTemplate.convertAndSend("DIRECT_EXCHANGE", "test.two",sendMsg,correlationData);
    }
}